<template>
  <div>
    <page-list :x-uri="uri" :custom-components="custom" :doactions="doactions">
      <!-- 自定义tab -->
      <template v-slot:page-tabs>
        <tabs />
      </template>
      <!-- 多选操作 -->
      <template v-slot:table-button="scope">
        <el-button v-auth="'mall.address.list.delete'" size="mini" @click="deletes(scope)">删除</el-button>
      </template>
    </page-list>
  </div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
import Tabs from './tabs';
export default {
  components: {
    PageList,
    Tabs
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/mall/admin/address/list',
      doactions: [{ title: '删除', meta: { permission: 'mall.address.list.delete' }, callback: this.delete }]
    };
  },
  methods: {
    delete: function({ row }) {
      this.deleteApi(row.id);
    },
    // 批量删除
    deletes: function({ rows }) {
      var ids = rows.map(row => row.id);
      if (ids.length === 0) {
        this.$message.warning('请选择要删除的地址');
        return false;
      }
      ids = ids.join(',');
      this.deleteApi(ids);
    },
    deleteApi: function(ids) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/mall/admin/address/' + ids,
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
